package org.pidan.basic.designModel.singleton;

/**
 * {@code @description}: 枚举
 * <p> 使用枚举实现单例模式优点:实现简单、调用效率高，枚举本身就是单例，由jvm从根本上提供保障!避免通过反射和反序列化的漏洞， 缺点没有延迟加载。
 * {@code @author}: huangyuxin
 * {@code @date}: 2023-11-15
 */
public class MeiJu {

    /**
     * 定义枚举
     */
    private static enum Anenum {

        INSTANCE;

        /**
         * 枚举元素为单例
         */
        private MeiJu meiJu;

        private Anenum() {
            System.out.println("枚举anenum私有构造参数");
            meiJu = new MeiJu();
        }

        public MeiJu getInstace() {

            return meiJu;
        }
    }

    public static MeiJu getInstance() {
        return Anenum.INSTANCE.getInstace();
    }

    public static void main(String[] args) {
        MeiJu meiJu1 = MeiJu.getInstance();
        MeiJu meiJu2 = MeiJu.getInstance();
        System.out.println(meiJu1 == meiJu2);

//        System.out.println(111);
    }
}
